package com.linkoog.devtools.code_generator.template.model.node;

import com.linkoog.devtools.code_generator.template.model.ContainerNodeData;
import com.linkoog.devtools.code_generator.template.render.engine.TemplateType;
import org.jetbrains.annotations.NotNull;

import java.io.Serializable;


public class TemplateNodeData extends ContainerNodeData implements Serializable {

    private static final long serialVersionUID = -200551574080571684L;


    public TemplateNodeData(){}

    public TemplateNodeData(@NotNull String name, @NotNull TemplateType templateEngineType) {
        this.name = name;
        this.templateEngineType = templateEngineType;
    }

    /**
     * 模板描述
     */
    private String description = "";
    /**
     * 模板引擎类型
     */
    private TemplateType templateEngineType;
    /**
     * 模板文件是否覆盖
     */
    private Boolean overwrite = Boolean.TRUE;
    /**
     * 模板文件编码
     */
    private String encoding = "UTF-8";

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public TemplateType getTemplateEngineType() {
        return templateEngineType;
    }

    public void setTemplateEngineType(TemplateType templateEngineType) {
        this.templateEngineType = templateEngineType;
    }

    public Boolean getOverwrite() {
        return overwrite;
    }

    public void setOverwrite(Boolean overwrite) {
        this.overwrite = overwrite;
    }

    public String getEncoding() {
        return encoding;
    }

    public void setEncoding(String encoding) {
        this.encoding = encoding;
    }

    @Override
    public TemplateNodeData copy() {
        TemplateNodeData templateNodeData = new TemplateNodeData();
        templateNodeData.setName(this.name);
        templateNodeData.setDescription(this.description);
        templateNodeData.setTemplateEngineType(this.templateEngineType);
        templateNodeData.setOverwrite(this.overwrite);
        templateNodeData.setEncoding(this.encoding);
        return templateNodeData;
    }

    @Override
    public TemplateNodeData deepCopy() {
        TemplateNodeData templateNodeData = copy();
        templateNodeData.addChildNode(copyList());
        return templateNodeData;
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) return true;
        if (object == null || getClass() != object.getClass()) return false;

        TemplateNodeData that = (TemplateNodeData) object;


        if (name != null ? !name.equals(that.name) : that.name != null) {
            return false;
        }
        if (description != null ? !description.equals(that.description) : that.description != null) {
            return false;
        }

        if (getChildNodeList() != null ?
                getChildNodeList().size() != that.getChildNodeList().size() || !getChildNodeList().equals(that.getChildNodeList())
                : that.getChildNodeList() != null) {
            return false;
        }

        return true;
    }

    @Override
    public String toString() {
        return "TemplateNodeData{" +
                " name='" + name + '\'' +
                ", childNodeList=" + getChildNodeList() +
                '}';
    }
}
